<?php

function pager_navigation($pager, $uri)
{
  $navigation = '';

  if ($pager->haveToPaginate())
  {
    $uri .= (preg_match('/\?/', $uri) ? '&' : '?').'page=';

    // First and previous page
    if ($pager->getPage() != 1)
    {
      $navigation .= link_to('<i>Première page</i>', $uri.'1', array('class' => 'btn first')); //image_tag('/sf/sf_admin/images/first.png', 'align=absmiddle')
      $navigation .= link_to('<i>Page précédente</i>', $uri.$pager->getPreviousPage(), array('class' => 'btn previous')).' '; //image_tag('/sf/sf_admin/images/previous.png', 'align=absmiddle')
    }

    // Pages one by one
    $links = array();
    foreach ($pager->getLinks() as $page)
    {
      $links[] = link_to_unless($page == $pager->getPage(), $page, $uri.$page);
    }
    $navigation .= join('  ', $links);

    // Next and last page
    if ($pager->getPage() != $pager->getLastPage())
    {
      $navigation .= ' '.link_to('<i>Page suivante</i>', $uri.$pager->getNextPage(), array('class' => 'btn next')); //image_tag('/sf/sf_admin/images/next.png', 'align=absmiddle')
      $navigation .= link_to('<i>Dernière page</i>', $uri.$pager->getLastPage(), array('class' => 'btn last')); //image_tag('/sf/sf_admin/images/last.png', 'align=absmiddle')
    }

  }

  return $navigation;
}